let utils = require('../../../../utils/util.js');
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		tissueunitcountIcon: [
			'http://ii.sinelinked.com/miniProgramAssets/sort_01.png',
			'http://ii.sinelinked.com/miniProgramAssets/sort_02.png',
			'http://ii.sinelinked.com/miniProgramAssets/sort_03.png',
			'http://ii.sinelinked.com/miniProgramAssets/sort_04.png'
		],
		tissueunitcount: [],
		tissuebyteam: [],
		tissueTypeNum:0,
		teamCardNum:0,
		teamTissueNum:0,
		num:0,
		_auth_team:'',
		url:''
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
	var {parentId,typeId} = options
	 var _auth_team = wx.getStorageSync('_auth')
	if(parentId){
		this.setData({
			url:'https://www.tcrunner.com/tissue_person/index.html?_auth='+_auth_team+'&parentId='+parentId+'&typeId='+typeId,
			_auth_team
		})
	}else{
		this.setData({
			url:'https://www.tcrunner.com/tissue_person/index.html?_auth='+_auth_team,
			_auth_team
		})
	}
	
	console.log(this.data.url);
   
    
		// this.tissueunitcount()
		// this.tissuebyteam()
		// this.tissuecount()
	},
	toNavigator(e) {
		var {
			url,
			typeid
		} = e.currentTarget.dataset
		utils.navigateTo({
			url: url + '?typeId=' + typeid
		})
	},
	toNavigator_next(e) {
		var {
			parentid,
			url,
			typeid
		} = e.currentTarget.dataset
		utils.navigateTo({
			url: url + '?parentId=' + parentid + '&typeId=' + typeid
		})
	},
	tissueunitcount() {
		utils.request(utils.personApi + '/team/find/tissueunitcount', 'GET')
			.then(res => {
				if (res.code == 0) {
					const tissueunitcount = res.data
					tissueunitcount.map((item, index) => {
						item.icon = this.data.tissueunitcountIcon[index]
					})
					this.setData({
						tissueunitcount
					})
				}
			})
	},
	// 查询当前团队所属的全部单位
	tissuebyteam() {
		utils.request(utils.personApi + '/team/find/tissuebyteam', 'GET')
			.then(res => {
				if (res.code == 0) {
					this.setData({
						tissuebyteam: res.data
					})
				}
			})
	},
	//统计组织分类
	tissuecount() {
		utils.request(utils.personApi + '/team/find/tissuecount', 'GET')
			.then(res => {
				if (res.code == 0) {
					const {tissueTypeNum,teamCardNum,teamTissueNum} = res.data
					const num = tissueTypeNum+teamCardNum+teamTissueNum
					console.log(tissueTypeNum/num);
					console.log(teamTissueNum/num);
					console.log(teamCardNum/num);
					this.setData({
						tissueTypeNum,
						teamCardNum,
						teamTissueNum,
						num
					})
				}
			})
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {

	}
})
